package com.securecrt.sql;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.provider.BaseColumns;
import android.util.Log;

import com.securecrt.pojo.Savesession;

public class SQLHelper extends SQLiteOpenHelper {

	private static final String DATABASE_NAME="savesession2.db";
	private static final int DATABASE_VERSION=1;
	//table name
	public static final String TABLE="sessions";
	//columns
	public static final String HOSTNAME="hostname";
	public static final String PORT="port";
	public static final String USERNAME="username";
	public static final String PASSWORD="password";
	
	public SQLHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
		// TODO Auto-generated constructor stub
	}
	
	@Override
	public void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		String sql="create table "+TABLE+"( "+BaseColumns._ID+" integer primary key autoincrement, "+HOSTNAME+" text null, "+PORT+" text null, "+USERNAME+" text null,"+PASSWORD+" text null);";
		Log.d("EventsData", "onCreate: "+sql);
		db.execSQL(sql);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		if(oldVersion>=newVersion)
			return;
		String sql=null;
		if(oldVersion==1)
			sql="alter table "+TABLE+" add not text;";
		if(oldVersion==2)
			sql="";
		if(sql!=null)
			db.execSQL(sql);
	}
}
